//
//  WXInputTableViewCell.m
//  CarJX
//
//  Created by King-ChenXu on 14-9-4.
//  Copyright (c) 2014年 KK. All rights reserved.
//

#import "WXInputTableViewCell.h"

@implementation WXInputCellObject

+(id)inputCellWithTitle:(NSString *)title value:(NSString *)value delegate:(id<UITextFieldDelegate>)delegate
{
    WXInputCellObject *inputcello = [WXInputCellObject new];
    inputcello.title = title;
    inputcello.value = value;
    inputcello.delegate = delegate;
    return inputcello;
}

-(UINib *)cellNib
{
    return [UINib nibWithNibName:@"WXInputTableViewCell" bundle:nil];
}
@end

@implementation WXInputTableViewCell

- (void)awakeFromNib
{
    // Initialization code
    [self.inputText addTarget:self action:@selector(textDidChange) forControlEvents:UIControlEventAllEditingEvents];
}

-(BOOL)shouldUpdateCellWithObject:(WXInputCellObject *)object
{
    WXInputCellObject *o = object;
    _inputCellObject = o;
    
     if (![o.value isEqual:[NSNull null]]) {
        self.inputText.text = o.value;

    }
        self.inputText.delegate = o.delegate;

     if (![o.title isEqual:[NSNull null]]) {
        self.titleLabel.text = o.title;
     }
 
    if (![o.placeholder isEqual:[NSNull null]]) {
        self.inputText.placeholder = o.placeholder;

    }
    if (![o.placeholder isEqual:[NSNull null]]) {
        self.inputTextLeftLabel.text = o.inputTextLeftText;

    }
    
     self.tag = o.tag;
    self.inputText.tag = o.tag;
    return YES;
}

-(void) textDidChange
{
    self.inputCellObject.value = self.inputText.text;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
